package org.yangjie.config.security;

import java.util.Collection;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

/**
 * 认证token实现
 * 模仿: org.springframework.security.authentication.UsernamePasswordAuthenticationToken
 * @author YangJie [2019年1月17日]
 */
@SuppressWarnings("serial")
public class TokenAuthenticationToken extends AbstractAuthenticationToken{
	
	private Object token;
	
	public TokenAuthenticationToken(Object token) {
		super(null);
		this.token = token;
	}
	public TokenAuthenticationToken(Object token, Collection<? extends GrantedAuthority> authorities) {
		super(null);
		this.token = token;
	}
	
	public TokenAuthenticationToken(Collection<? extends GrantedAuthority> authorities) {
		super(authorities);
		super.setAuthenticated(true); // 防止provider进行两次验证
	}

	@Override
	public Object getCredentials() {
		return token;
	}

	@Override
	public Object getPrincipal() {
		return null;
	}
	
}
